package jcrosswords.domain;

import java.awt.Font;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;

@Entity
public class Crossword implements Serializable {
	
	private static final long serialVersionUID = 1L;
	
	private Long id;
	private Integer height;
	private Integer width;
	private Collection<ClueResponseTag> clueResponseTags;
	private Font font;
	
	public Crossword() {
	}
	
	public Crossword(Integer height, Integer width, Collection<ClueResponseTag> clueResponseTags, Font font) {
		setHeight(height);
		setWidth(width);
		setClueResponseTags(clueResponseTags);
		setFont(font);
	}
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public Long getId() {
		return id;
	}
	
	private void setId(Long id) {
		this.id = id;
	}

	public Integer getHeight() {
		return height;
	}
	
	private void setHeight(Integer height) {
		this.height = height;
	}
	
	public Integer getWidth() {
		return width;
	}
	
	private void setWidth(Integer width) {
		this.width = width;
	}
	
	@OneToMany
	public Collection<ClueResponseTag> getClueResponseTags() {
		if(clueResponseTags == null)
			clueResponseTags = new ArrayList<ClueResponseTag>();
		return clueResponseTags;
	}
	
	private void setClueResponseTags(
			Collection<ClueResponseTag> clueResponseTags) {
		if(clueResponseTags == null) {
			clueResponseTags = new ArrayList<ClueResponseTag>();
		}
		this.clueResponseTags = clueResponseTags;
	}

	public Font getFont() {
		return font;
	}
	
	private void setFont(Font font) {
		this.font = font;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final Crossword other = (Crossword) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
	
	public String toString() {
		return id.toString();
	}

}